package com.dgh.school.controller;


import com.dgh.school.bean.Schedule;
import com.dgh.school.common.R;
import com.dgh.school.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;



@RestController
public class ScheduleController {
    @Autowired
    private ScheduleService scheduleService;

    @RequestMapping("/schedule")
    public R selectByPage(int pageNum, int pageSize){
        try {
            return scheduleService.selectByPage(pageNum,pageSize);
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/schedule/delete")
    public R deleteSchedule(int id){
        try {
            scheduleService.deleteSchedule(id);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/schedule/add")
    public R add(Schedule schedule){
        try {
            scheduleService.insertData(schedule);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    @RequestMapping("/schedule/modify")
    public R modify(Schedule schedule){
        try {
            scheduleService.updateData(schedule);
//            System.out.println(schedule);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }
}
